package string_;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Connect
 * Package: string_
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-11-29
 * Time: 20:32
 */

public class Connect {

    //字符串拼接操作

    public static void main(String[] args) {
        String s1 = "hello";
        String s2 = "world";
        String s3 = "helloworld";
        //这可以算是常量拼接
        String s4 = "hello" + "world"; //字节码文件当中就是helloworld

        //这些都是有变量参与的 是底层新new了一个对象
        String s5 = s1 + "world";
        String s6 = "hello" + s2;
        String s7 = s1 + s2;
        System.out.println(s3 == s4); //t
        System.out.println(s3 == s5); //f
        System.out.println(s3 == s6); //f
        System.out.println(s3 == s7); //f
        System.out.println(s5 == s6); //f
        System.out.println(s5 == s7); //f

        // intern 产生一个新的字符串
        String intern = s5.intern();
        //和 s3 是 ture 说明返回的是字符串常量池字面量的地址
        //因为字符串常量池中不能存在相同的 把已经的地址给他就行了
        System.out.println(intern == s3); //t

    }
}
